/*
 * PopupLogsDialog.cpp
 *
 *  Created on: Nov 26, 2012
 *      Author: guillou
 */

#include <QDialog>
#include <PopupLogsDialog.hpp>

using namespace PopupUtils;

PopupLogsDialog::PopupLogsDialog(QWidget *p_parent)
 : QDialog(p_parent)
{
  setupUi(this);
  connect(this, SIGNAL(signal_logMessage(const QString &)),
          this, SLOT(slot_logMessage(const QString &)));
  PopupUtils::LoggerUI::init(this);
}

void PopupLogsDialog::logmsg(LogLevel p_level, const char *p_format, va_list p_args) {
  QString _msg;
  char _log[1024];
  vsprintf(_log, p_format, p_args);
  switch (p_level) {
    case POPUP_LOG_TRACE:
      _msg = "<font color='#777777'><b>TRACE:</b> ";
      break;
    case POPUP_LOG_INFO:
      _msg = "<font color='blue'><b>INFO:</b> ";
      break;
    case POPUP_LOG_WARNING:
      _msg = "<font color='orange'><b>WARNING:</font></b> ";
      break;
    case POPUP_LOG_ERROR:
      _msg = "<font color='red'><b>ERROR:</font></b> ";
      break;
    case POPUP_LOG_CRITICAL:
      _msg = "<u><font color='purple'><b>CRITICAL:</b></u> ";
      break;
  }
  _msg = _msg + _log + "</font><br>";
  emit signal_logMessage(_msg);
}

void PopupLogsDialog::slot_logMessage(const QString & p_message)
{
  m_logsEdit->insertHtml(p_message);
}

